package com.jt.www.admin.pay.controller;

import com.jt.www.admin.pay.service.PayStateService;
import com.jt.www.enums.ResultEnum;
import com.jt.www.model.reps.ResultDTO;
import com.jt.www.model.woxuebao.PayStateDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author admin_ltf
 * @create 2019-05-18 10:56
 */
@Api(value = "我学保支付回调", tags = {"PAY-MANAGE-API"}, description = "我学保")
@RestController
@RequestMapping(value = "/api/v1/payState")
public class PayStateEndpoint {

    public static final Logger log = LoggerFactory.getLogger(PayStateEndpoint.class);
    @Autowired
    private PayStateService payStateService;

    /**
     * 更新支付状态
     *
     * @param payStateDTO
     * @return
     */
    @ApiOperation(value = "支付回调接口更新支付状态", notes = "支付回调接口更新支付状态", httpMethod = "POST")
    @PostMapping(value = "")
    public ResultDTO changePayState(@RequestBody PayStateDTO payStateDTO) {

        if (payStateDTO == null) {
            return new ResultDTO(ResultEnum.PARAM_ERROR, "参数不能为空");
        }

        ResultDTO dto = null;
        try {
            dto = payStateService.changePayState(payStateDTO);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultDTO(ResultEnum.SERVER_ERROR, "请求失败");
        }

        return dto;
    }

}
